package app.fugema.shop.main.evaluate.adapter;

import android.view.View;

import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.SingleRecyclerAdapter;
import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.widget.nineImageView.ImagesActivity;
import app.fugema.shop.R;
import app.fugema.shop.databinding.EvaluateGoodsItemBinding;
import app.fugema.shop.databinding.EvaluateImagesItemBinding;
import app.fugema.shop.main.evaluate.model.EvaluateBean;

import java.util.Arrays;

public class EvaluateGoodsItemAdapter extends SingleRecyclerAdapter<EvaluateBean, EvaluateGoodsItemBinding>
{

    @Override
    public int getLayoutId()
    {
        return R.layout.evaluate_goods_item;
    }

    @Override
    public void onCreateViewHolder(EvaluateGoodsItemBinding binding, BaseViewHolder viewHolder) {
        super.onCreateViewHolder(binding, viewHolder);
        binding.rvRecyclerViewImages.setAdapter(new SingleRecyclerAdapter<String, EvaluateImagesItemBinding>() {
            @Override
            public int getLayoutId() {
                return R.layout.evaluate_images_item;
            }

            @Override
            public void onBindViewHolder(EvaluateImagesItemBinding binding, int position, String bean) {
                super.onBindViewHolder(binding, position, bean);
                binding.givImage.loadUrl(bean);
            }

            @Override
            public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, String bean) {
                super.onItemClick(view, adapter, onclickType, position, bean);
                ImagesActivity.startActivity(binding.rvRecyclerViewImages, R.id.givImage, null, position);
            }
        });
    }

    @Override
    public void onBindViewHolder(EvaluateGoodsItemBinding binding, int position, BaseViewHolder viewHolder, EvaluateBean bean)
    {
        super.onBindViewHolder(binding, position, viewHolder, bean);
        if (binding.rvRecyclerViewImages.getAdapter() instanceof BaseRVAdapter)
        {
            BaseRVAdapter rvAdapter = (BaseRVAdapter) binding.rvRecyclerViewImages.getAdapter();
            if (UIUtils.isEmpty(bean.getImages()))
            {
                rvAdapter.clear();
            }
            else
            {
                // Arrays.asList()  .split(",")
                rvAdapter.setDataList(  bean.getImages());
            }
        }
    }

}
